package jtk.project4.fleet.screen.costStatistic;



import java.awt.FlowLayout;

//import jtk.project4.fleet.field.GeneralInformationField;
import jtk.project4.fleet.domain.Objects;
import jtk.project4.fleet.domain.PmHist;
import jtk.project4.fleet.field.PartUsedField;
import jtk.project4.fleet.field.ViewSettingsField;
import jtk.project4.fleet.field.LaborDetailsField;
import jtk.project4.fleet.field.PreventiveMaintenanceField;
import jtk.project4.fleet.field.RepairsField;
import jtk.project4.fleet.field.CostStatisticSelectField;
import nl.coderight.jazz.action.Action;
import nl.coderight.jazz.form.FormField;
import nl.coderight.jazz.form.FormHeader;
import nl.coderight.jazz.form.FormLayout;
import nl.coderight.jazz.form.FormView;
import nl.coderight.jazz.form.control.GroupControl;
import nl.coderight.jazz.form.control.TabControl;
import nl.coderight.jazz.form.control.TabItem;
import nl.coderight.jazz.form.field.ComboField;
import nl.coderight.jazz.form.field.SelectField;
import nl.coderight.jazz.form.field.TableField;
import nl.coderight.jazz.form.field.TextField;
import nl.coderight.jazz.form.field.button.PushButton;

public class CostStatisticView extends FormView {
	private FormHeader equipSlctHeader;
	private TabControl costStatisticTab;
	private TabItem preventiveMaintenanceTab;
	private TabItem repairsTab;
	private TabItem partUsedTab;
	private TabItem laborDetailsTab;
	private PushButton printButton;
	private PushButton helpButton;
	private PushButton closeButton;
	private Action printAction;
	private Action helpAction;
	private Action closeAction;
	private TableField<PmHist> pmTable;
	private TableField<PmHist> rprTable;
	private SelectField<Objects> equipselectField;
		
	@Override
	protected void init() {
		// TODO Auto-generated method stub
		createTabFields();
		createFields();
		createLayout();
		
	}

	private void createTabFields() {
		// TODO Auto-generated method stub
		
		costStatisticTab = new TabControl();
		preventiveMaintenanceTab = new TabItem("Preventive Maintenance");
		repairsTab = new TabItem("Repairs");
		partUsedTab = new TabItem("Part Used");
		laborDetailsTab = new TabItem("Labor Details");
	}

	private void createLayout() {
		// TODO Auto-generated method stub
		addField(createForm());
	}

	private FormHeader createHeader() {
		equipSlctHeader = new FormHeader();
		equipSlctHeader.setTitle("Equipment Selection");
		equipselectField = new SelectField<Objects>("objectTitle", "objectTitle");
		return equipSlctHeader;
	}
	
	private void createFields() {
		// TODO Auto-generated method stub
		printButton = new PushButton("printAction");
		helpButton = new PushButton("helpAction");
		closeButton = new PushButton("closeAction");
		
	}
	
	private GroupControl createForm() {
		GroupControl form = new GroupControl();
		form.addField(createSelect(), NORTH);
		form.addField(createTabs(), CENTER);
		form.addField(createButtons(), SOUTH);
		return form;
		}

	private FormField createButtons() {
		// TODO Auto-generated method stub
		GroupControl buttons = new GroupControl();
		buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
		buttons.addField(printButton);
		buttons.addField(helpButton);
		buttons.addField(closeButton);
		return buttons;
		
	}

	private FormField createTabs() {
		// TODO Auto-generated method stub
		TabControl form = costStatisticTab;
		form.addTab(preventiveMaintenanceTab, createPMTab());
		form.addTab(repairsTab, createRPTab());
		form.addTab(partUsedTab, createPUTab());
		form.addTab(laborDetailsTab, createLDTab());
		return form;
		
	}
	
	private FormField createPMTab() {
		// TODO Auto-generated method stub
		GroupControl form = new GroupControl();
		pmTable = new TableField<PmHist>("pmHists","pmHist");
		pmTable.addColumn("PM Service", "mtcPerf");
		pmTable.addColumn("Part Cost", "pCost");
		pmTable.addColumn("Labor Cost", "lCost");
		pmTable.addColumn("Total Cost", "cost");
		pmTable.addColumn("% of Total", "0");
		
		form.setLayout(new FormLayout())	
		.addField(pmTable)
		.addRow()
		.addField(new ViewSettingsField(" "))
		.addRow();
		return form;
	}


	private FormField createRPTab() {
		// TODO Auto-generated method stub
		GroupControl form = new GroupControl();
		rprTable = new TableField<PmHist>("pmHists","pmHist");
		rprTable.addColumn("Repairs", "mtcPerf");
		rprTable.addColumn("Part Cost", "pCost");
		rprTable.addColumn("Labor Cost", "lCost");
		rprTable.addColumn("Total Cost", "cost");
		rprTable.addColumn("% of Total", "0");
		
		form.setLayout(new FormLayout())	
		.addField(rprTable)
		.addRow()
		.addField(new ViewSettingsField(" "))
		.addRow();
		return form;
	}
	
	private FormField createSelect() {
		// TODO Auto-generated method stub
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())	
		.addField(new CostStatisticSelectField(" "));
		return form;
	}
	
	private FormField createLDTab() {
		// TODO Auto-generated method stub
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())	
		.addField(new LaborDetailsField(" "))
		.addRow()
		.addField(new ViewSettingsField(" "))
		.addRow();
		return form;
	}

	private FormField createPUTab() {
		// TODO Auto-generated method stub
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())	
		.addField(new PartUsedField(" "))
		.addRow()
		.addField(new ViewSettingsField(" "))
		.addRow();
		return form;
	}

	private FormField createGeneralTab() {
		// TODO Auto-generated method stub
		//hanya display untuk image(gmbar) yang telah dipilih
		GroupControl form = new GroupControl();
		form.setLayout(new FormLayout())	
			.addField(new ViewSettingsField(" "));
		return form;
	}


}
